<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="UTF-8" />
		<title>菜单管理</title>
		<div th:replace="common/common_grid_header"></div>
	</head>
	<body style="overflow: auto;">
		<fieldset class="layui-elem-field">
		    <div class="layui-field-box">
		        <div class="layui-inline">
		            <a class="layui-btn layui-btn-sm layui-btn-normal" data-type="addUser" id="add-per"> <i class="layui-icon">&#xe61f;</i>新增</a>
		        </div>
		    </div>
		</fieldset>
		
		<div style="height: 100%">
			<div class="layui-row"> 
				<table id="pertable" class="layui-table" lay-filter="pertable"></table> 
			</div>
		</div>
		
		<script type="text/html" id="toolBar">
  			<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>
  			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
		</script>
	</body>
	<script>
		layui.config({
		    base: '/js/plugin/layui-v2.3.0/layui/module/'
		}).extend({
		    treetable: 'treetable-lay/treetable'
		}).use(['treetable','table','layer'], function () {
		    var treetable = layui.treetable,table=layui.table;
		    
			// 渲染表格
		    treetable.render({
		        treeColIndex: 1,          // treetable新增参数
		        treeSpid: 'root',             // treetable新增参数
		        treeIdName: 'id',       // treetable新增参数
		        treePidName: 'parentid',     // treetable新增参数
		        treeDefaultClose: true,   // treetable新增参数
		        treeLinkage: false,        // treetable新增参数
		        elem: '#pertable',
		        url: '/system/org/permission/getTreeTableJson',
		        cols: [[
		            {type: 'numbers'},
		           // {field: 'id', title: 'id'},
		            //{field: 'parentid', title: 'parentid'},
		            {field: 'permissionname', title: 'permissionname'},
		            {field: 'type', title: 'type'},
		            {field: 'permission', title: 'permission'},
		            {title: '操作',toolbar:'#toolBar',width:150,align:"center"}
		        ]]
		    });
			
		    table.on('tool(pertable)',function(obj){
		    	console.log(obj);
		    	if(obj.event=="edit"){
		    		layer.open({//编辑页面
						type: 2,
						title: '编辑菜单项',
						shadeClose: false,
						shade: 0.1,
						offset:'10%',
						area: ['80%', '80%'],
						content: '/system/org/permission/toEdit?id='+obj.data.id //iframe的url
					});
		    	}else if(obj.event=="del"){
		    		layer.confirm('删除确认!',{
			      		offset:'10%',
						shade: 0.1
			      	},function(){
			    		$.getJSON("/system/org/permission/delete",{id:obj.data.id},function(res){
			    			if(res.code==200){
			    				layer.alert(res.msg,function(){
			    					layer.closeAll();
						    		obj.del();
			    				});
			    			}
			    		});
		    		});
		    	}
		    });
			
			//加载事件
			$("#add-per").click(function(){//新增页面
				layer.open({
					type: 2,
					title: '新增菜单项',
					shadeClose: false,
					shade: 0.1,
					offset:'10%',
					area: ['80%', '80%'],
					content: '/system/org/permission/toAdd' //iframe的url
				}); 
			});
		});
	
	</script>
</html>